package com.example.demo.mapper;

import com.example.demo.model.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("SELECT * FROM category ORDER BY sort ASC")
    List<Category> findAll();

    @Select("SELECT * FROM category WHERE category_id = #{id}")
    Category findById(Integer id);

    @Insert("INSERT INTO category(name, sort) VALUES(#{name}, #{sort})")
    @Options(useGeneratedKeys = true, keyProperty = "categoryId")
    int insert(Category category);

    @Update("UPDATE category SET name=#{name}, sort=#{sort} WHERE category_id=#{categoryId}")
    int update(Category category);

    @Delete("DELETE FROM category WHERE category_id=#{id}")
    int delete(Integer id);
}